package com.wy.authority.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wy.authority.entity.Role;
import com.wy.authority.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * @Author 忘忧
 * @Date Created in 2021/1/12 13:54
 * @Description:
 */
@RestController
@RequestMapping("/role")
public class RoleController {
    @Autowired
    private RoleService roleService;


    //分页
    @ResponseBody
    @GetMapping("/findall")
    public PageInfo<Role> findAll(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "5") Integer size){
        PageHelper.startPage(page,size);
        List<Role> list=roleService.find();
        PageInfo<Role> pageInfo =new PageInfo<>(list);
        return pageInfo;
    }

    @PostMapping("/insert")
    public String insert(@RequestBody Role role) {
        role.setCreate_time(new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(new Date()));
        System.out.println(role);
        roleService.insert(role);
        return "success";
    }
}
